package qlttn.business;

import java.sql.SQLException;
import java.util.ArrayList;

import qlttn.common.utility.LoggerUtility;
import qlttn.common.valueobjects.UserVO;
import qlttn.dao.daointerface.UserDAO;
import qlttn.dao.daointerface.UserDAOImpl;
import qlttn.web.bean.UserBean;

public class UserBOImpl implements UserBO {
	UserDAO userDAO = null;

	/*
	 * (non-Javadoc)
	 * 
	 * @see qlttn.business.UserBO#logon(qlttn.web.bean.UserBean) Check userName
	 * and password then store password to the session.
	 * 
	 * @param userBean
	 * 
	 * @return boolean
	 */
	@Override
	public boolean logon(UserVO userVO) throws SQLException,
			ClassNotFoundException {
		LoggerUtility.logger("UserBOImpl.logon()..............start");
		userDAO = new UserDAOImpl();
		userVO = userDAO.getUserByPassword(userVO);
		if (userVO != null) {
			return true;
		}
		LoggerUtility.logger("UserBOImpl.logon()..............end");
		return false;
	}

	@Override
	public boolean register(UserBean userBean) throws SQLException,
			ClassNotFoundException {
		LoggerUtility.logger("UserBOImpl.register()..............start");
		
		
		
		LoggerUtility.logger("UserBOImpl.register()..............end");
		return false;
	}

	@Override
	public UserVO showProfile(String userName) throws SQLException,
			ClassNotFoundException {
		LoggerUtility.logger("UserBOImpl.showProfile()..............start");
		userDAO = new UserDAOImpl();
		UserVO userVO = userDAO.getUserInfo(userName);
		LoggerUtility.logger("UserBOImpl.showProfile()..............end");
		return userVO;
	}

	/**
	 * Get list of user from the database.
	 * 
	 * @param role
	 * @return ArrayList<UserVO>
	 * @throws SQLException
	 * @throws ClassNotFoundException
	 */
	@Override
	public ArrayList<UserVO> getListUsers(String role) throws SQLException,
			ClassNotFoundException {
		LoggerUtility.logger("UserBOImpl.getListUsers()..............start");
		userDAO = new UserDAOImpl();
		ArrayList<UserVO> listUsers = userDAO.getListUsers(role);
		LoggerUtility.logger("UserBOImpl.getListUsers()..............end");
		return listUsers;
	}

}
